<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    exclude-result-prefixes="">
    <xsl:output method="xml" indent="yes"/>
    <xsl:template match="/">
        <doc>
            <xsl:apply-templates/>
        </doc>
    </xsl:template>
	
	<xsl:template match="text()|@*" />
	
    <xsl:template match="main">
        <field name="subject">
            <xsl:value-of select="."/>
        </field>
        <xsl:if test="following-sibling::sub">
	        <field name="subject">
	            <xsl:value-of select="."/> - <xsl:value-of select="following-sibling::sub" />
	        </field>
        </xsl:if>
        <field name="s_m_s_metalibPrimaryCategory">
        	<xsl:value-of select="."/>
        </field>
    </xsl:template>
    
    <xsl:template match="sub">
    	<field name="s_m_s_metalibSecondaryCategory">
        	<xsl:value-of select="."/>
        </field>
    </xsl:template> 

</xsl:stylesheet>
